package com.leoman.spinningmachine.tab1;

import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.leoman.spinningmachine.R;
import com.leoman.spinningmachine.base.BaseFragment;
import com.leoman.spinningmachine.util.QRCodeUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 二维码
 */
public class OcrFragment extends BaseFragment {

    @BindView(R.id.tv_left)
    TextView tvLeft;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.ll_left)
    LinearLayout ll_left;
    @BindView(R.id.ll_right)
    LinearLayout ll_right;
    @BindView(R.id.iv_ocr)
    ImageView iv_ocr;
    private int result;

    protected int getContentViewLayoutID() {
        return R.layout.fg_ocr;
    }

    @Override
    protected void initView(View view) {
//        MainServer.doStart();
//        MainServer.setQrCodeGenerate(new DefaultQrCodeGenerate());
//        result = MainServer.openDoor(Constant.DEVICE_MAC,Constant.DEVICE_MAC+"&"+new Date().getTime(),1);
    }

    @Override
    protected void initData() {
        QRCodeUtil.createQR(getActivity(), iv_ocr, "绍纺机");
    }

    @OnClick({R.id.tv_left, R.id.tv_right})
    void click(View view) {
        switch (view.getId()) {
            case R.id.tv_left:
                changeUI(tvLeft, tvRight, true);
                break;
            case R.id.tv_right:
                changeUI(tvRight, tvLeft, false);
                break;
        }
    }

    private void changeUI(TextView textView1, TextView textView2, boolean isLeft) {
        textView1.setTextColor(ContextCompat.getColor(getActivity(), R.color.white));
        textView2.setTextColor(ContextCompat.getColor(getActivity(), R.color.green_10));
        textView1.setBackgroundResource(isLeft ? R.drawable.ic_ocr_top_left_bg : R.drawable.ic_ocr_top_right_bg);
        textView2.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.trans));
        ll_left.setVisibility(isLeft ? View.VISIBLE : View.GONE);
        ll_right.setVisibility(!isLeft ? View.VISIBLE : View.GONE);
    }

}
